package spring.aop.proxy

import org.aspectj.lang.JoinPoint
import org.aspectj.lang.ProceedingJoinPoint
import org.aspectj.lang.annotation.After
import org.aspectj.lang.annotation.Around
import org.aspectj.lang.annotation.Aspect
import org.aspectj.lang.annotation.Before
import org.aspectj.lang.annotation.Pointcut
import org.springframework.stereotype.Component

@Component
@Aspect
internal class AspectService {

    @Pointcut(value = "execution(* spring.aop.proxy.*.*(..))")
    fun pointCut() {
    }

    @Before(value = "pointCut()")
    fun doBefore(joinPoint: JoinPoint) {
        System.out.println("AOP Before Advice... ")
    }

    @After(value = "pointCut()")
    fun doAfter(joinPoint: JoinPoint) {
        System.out.println("AOP After Advice... ")
    }

    @Around(
        value = "execution(* spring.aop.proxy.PointCutServiceTwo.test(String))" +
                " && args(id)",argNames = "id")
    fun test(
        pjp: ProceedingJoinPoint,id:String
    ): Any {
        println("AspectService"+ id)
        return "bb"
    }
}